define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var assistantId = 0;
    var Controller = {
        index: function () {
            assistantId = $('#assistantId').val();
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'assistant/withdraw/index' + location.search + '&sid='+assistantId,
                    // add_url: 'assistant/withdraw/add',
                    edit_url: 'assistant/withdraw/edit',
                    del_url: 'assistant/withdraw/del',
                    multi_url: 'assistant/withdraw/multi',
                    import_url: 'assistant/withdraw/import',
                    table: 'assistant_withdraw',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        //{field: 'assistant_id', title: __('Assistant_id')},
                        //{field: 'user_id', title: __('User_id')},
                        {field: 'assistant.nickname', title: __('Assistant.nickname'), operate: 'LIKE'},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"wechat":__('Type wechat'),"alipay":__('Type alipay')}, formatter: Table.api.formatter.normal},
                        {field: 'order', title: __('Order'), operate: 'LIKE'},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'third_order', title: __('Third_order'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'reviewerName', title: __('Reviewer'),operate: false},
                        {field: 'review_status', title: __('Review_status'), searchList: {"0":__('Review_status 0'),"1":__('Review_status 1'),"2":__('Review_status 2')}, formatter: Table.api.formatter.status},
                        //{field: 'is_system', title: __('Is_system'), searchList: {"0":__('Is_system 0'),"1":__('Is_system 1')}, formatter: Table.api.formatter.normal},
                        {field: 'reason', title: __('Reason'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
                                {
                                    name:'审核',
                                    extend:'data-area=["90%","90%"]',
                                    title:'审核',
                                    text:'审核',
                                    icon:'fa fa-magic',
                                    classname:'btn btn-xs btn-success btn-dialog',
                                    url:'assistant/withdraw/edit',
                                    visible:function (row) {
                                        console.log(row);
                                        if (row.review_status > 0){
                                            return false;
                                        }else{
                                            return true;
                                        }
                                    },
                                    refresh:true
                                }
                            ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
